<template>
  <div class="home-brand">
    <homePanel title="热门品牌" sub-title="国际经典 品质保证">
      <template #right>
        <a
          @click="PAGE_NUM = 0"
          href="javascript:;"
          :class="{ disabled: PAGE_NUM === 0 }"
          class="iconfont icon-angle-left prev"
        ></a>
        <a
          @click="PAGE_NUM = 1"
          href="javascript:;"
          :class="{ disabled: PAGE_NUM === 1 }"
          class="iconfont icon-angle-right next"
        ></a>
      </template>

      <div class="box" ref="box">
        <Transition name="fade">
          <ul class="list" v-if="BRANDLIST.length" :style="`transform:translateX(${PAGE_NUM === 0 ? '0':'-50%'})`">
            <li v-for="item in BRANDLIST" :key="item">
              <RouterLink to="/">
                <img :src="item.picture" />
              </RouterLink>
            </li>
          </ul>
          <div v-else class="skeleton">
            <xtx-skeleton
              class="item"
              v-for="i in 5"
              :key="i"
              width="240px"
              height="305px"
              bg="#e4e4e4"
            ></xtx-skeleton>
          </div>
        </Transition>
      </div>
    </homePanel>
  </div>
</template>

<script setup name:home-brand>
import { findBrand } from "@/api/home.js";
import { lazyLoadingFn } from "@/hooks/index.js";
import homePanel from "@/views/Home/components/home-panel";
import { ref } from "vue-demi";
// 切换页码
const PAGE_NUM = ref(0);
const { target: box, data: BRANDLIST } = lazyLoadingFn(findBrand);
</script>

<style scoped lang="less">
.home-panel {
  background: #f5f5f5;
}
.iconfont {
  width: 20px;
  height: 20px;
  background: #ccc;
  color: #fff;
  display: inline-block;
  text-align: center;
  margin-left: 5px;
  background: @xtxColor;
  &::before {
    font-size: 12px;
    position: relative;
    top: -2px;
  }
  &.disabled {
    background: #ccc;
    cursor: not-allowed;
  }
}
.box {
  display: flex;
  width: 100%;
  height: 345px;
  overflow: hidden;
  padding-bottom: 40px;
  .list {
    width: auto;
    display: flex;
    transition: all 0.4s;
    li {
      margin-right: 10px;
      width: 240px;
      &:nth-child(5n) {
        margin-right: 0;
      }
      img {
        width: 240px;
        height: 305px;
      }
    }
  }
}
.skeleton {
  width: 100%;
  display: flex;
  .item {
    margin-right: 10px;
    &:nth-child(5n) {
      margin-right: 0;
    }
  }
}
</style>
